package cn.ultrarisk.scadmin.manager.biz.monitor.dao;

import cn.ultrarisk.mybatis.extension.domain.Page;
import cn.ultrarisk.mybatis.extension.query.Query;
import cn.ultrarisk.scadmin.manager.biz.monitor.entity.ErrorLog;
import cn.ultrarisk.scadmin.manager.support.BaseDAO;
import org.springframework.stereotype.Repository;

/**
 * 错误日志数据操作类
 *
 * @author sevendlong(lin23871@163.com)
 * @date 2014/3/28
 * @since V1.0
 */
@Repository
public class ErrorLogDAO extends BaseDAO<ErrorLog, Long> {
    /**
     * 构造器
     */
    public ErrorLogDAO() {
        super(ErrorLog.class, ErrorLog.COLUMN_PROPERTY_MAP);
    }

    public Page<ErrorLog> findPage(Integer collectionId, String target, String message, Long errStartTime, Long errEndTime, int pageNo, int pageSize) {
        Query query = Query.query(ErrorLog.COLLECTION_ID, collectionId);
        query.like(ErrorLog.TARGET, target).like(ErrorLog.MESSAGE, message);
        if (errStartTime != null && errStartTime > 0) {
            query.gt(ErrorLog.ERROR_TIME, errStartTime);
        }
        if (errEndTime != null && errEndTime > 0) {
            query.lt(ErrorLog.ERROR_TIME, errEndTime);
        }
        query.addSort(ErrorLog.ERROR_TIME, Query.Direction.DESC);
        return findPage(query, pageNo, pageSize, ErrorLog.ID, ErrorLog.COLLECTION_ID, ErrorLog.TARGET, ErrorLog.IP, ErrorLog.ERROR_TIME);
    }
}
